package com.lry.crawlers.fiction.service.impl;

import com.lry.crawlers.fiction.entity.FictionVariable;
import com.lry.crawlers.fiction.mapper.FictionVariableMapper;
import com.lry.crawlers.fiction.service.FictionVariableService;
import com.lry.crawlers.util.ProcessVariable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.List;

@Service
public class FictionVariableServiceImpl implements FictionVariableService {
    @Autowired
    FictionVariableMapper fictionVariableMapper;
    //初始化FictionVariable信息
    @PostConstruct
    private void initialize() {
        List<FictionVariable> fictionVariables = getFictionVariables();
        for (FictionVariable f: fictionVariables){
            ProcessVariable.setFVariable(f.getId(),f);
        }

    }

    public void update(){
        initialize();
    }

    @Override
    public int setFictionVariable(FictionVariable fictionVariable) {
        int insert = fictionVariableMapper.insert(fictionVariable);
        return insert;
    }

    @Override
    public List<FictionVariable> getFictionVariables() {
        return fictionVariableMapper.selectList(null);
    }

}
